<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item, index) in tabbarList" :key="index" :class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
				<view class="item-top"><image :src="currentItem == item.id ? item.selectIcon : item.icon"></image></view>
				<view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
					<text>{{ item.text }}</text>
				</view>
			</view>
		</block>
	</view>
</template>
 
<script>
export default {
	props: {
		currentPage: {
			type: Number,
			default: 0
		}
	},
	data() {
		return {
			currentItem: 0,
			IMAGE_STATIC: this.$url.assetsPath, // 静态图片地址
			tabbarList: [
				{
					id: 0,
					path: '/pagesMain/index/index',
					icon: this.$url.assetsPath+'/tabbar/icon-tabbar-1.png',
					selectIcon: this.$url.assetsPath+'/tabbar/icon-tabbar-1-active.png',
					text: '首页',
					centerItem: false
				},
				{
					id: 1,
					path: '/pagesMain/statistics/statistics',
					icon: this.$url.assetsPath+'/tabbar/icon-tabbar-2.png',
					selectIcon: this.$url.assetsPath+'/tabbar/icon-tabbar-2-active.png',
					text: '统计',
					centerItem: false
				},
				{
					id: 2,
					path: '/pagesMain/user/user',
					icon: this.$url.assetsPath+'/tabbar/icon-tabbar-3.png',
					selectIcon: this.$url.assetsPath+'/tabbar/icon-tabbar-3-active.png',
					text: '我的',
					centerItem: false
				},
			],
			usermsg: uni.getStorageSync('usermsg') ? uni.getStorageSync('usermsg') : {real_name:''}
		};
	},
	mounted() {
		this.currentItem = this.currentPage;
		uni.hideTabBar();
	},
	methods: {
		changeItem(item) {
			let _this = this;
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route // 获取当前页面路由，也就是最后一个打开的页面路由
			//_this.currentItem = item.id;
			if('/'+curRoute != item.path){
				uni.redirectTo({
					url: item.path
				});
			}
		}
	}
};
</script>
<style>
view {
	padding: 0;
	margin: 0;
	box-sizing: border-box;
}
.tabbar-container {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 130rpx;
	box-shadow: 0 0 5px #fff;
	display: flex;
	align-items: center;
	padding: 15rpx 0 35rpx;
	color: #999999;
	background: #ffffff;
	border-top: 1px solid #EEEEEE;
}
.tabbar-container .tabbar-item {
	width: 33.3%;
	height: 118rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
	color: #232323;
}
.tabbar-container .item-active {
	color: #AD2926;
}
.tabbar-container .center-item {
	display: block;
	position: relative;
}
.tabbar-container .tabbar-item .item-top {
	width: 48rpx;
	height: 48rpx;
}
.tabbar-container .center-item .item-top {
	flex-shrink: 0;
	width: 200rpx;
	height: 90rpx;
	position: absolute;
	top: 10rpx;
	left: calc(50% - 100rpx);
}
.tabbar-container .tabbar-item .item-top image {
	width: 100%;
	height: 100%;
}
.tabbar-container .tabbar-item .item-bottom {
	font-size: 28rpx;
	width: 100%;
}
.tabbar-container .center-item .item-bottom {
	position: absolute;
	bottom: 5rpx;
}
</style>